package com.wpml.juc;

import java.util.concurrent.*;

/**
 * @Description
 * @Date 2021-07-01
 * @Author wangpei
 **/
public class ThreadPoolExecutorTest {

    static class MyThreadPool extends ThreadPoolExecutor{
        public MyThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler) {
            super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
        }

        @Override
        protected void afterExecute(Runnable r, Throwable t) {
            super.afterExecute(r, t);
//            int i = 1/0;
        }
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        /*MyThreadPool myThreadPool = new MyThreadPool(1, 1, 0, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), r -> {
            Thread thread = new Thread(r);
            thread.setUncaughtExceptionHandler((t, e) -> System.out.println("出异常了" + e.getMessage()));
            return thread;
        }, new ThreadPoolExecutor.CallerRunsPolicy());


        myThreadPool.execute(() -> System.out.println(Thread.currentThread()));
        myThreadPool.execute(() -> System.out.println(Thread.currentThread()));
        myThreadPool.execute(() -> System.out.println(Thread.currentThread()));

        myThreadPool.shutdown();*/


        CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> System.out.println("123"));

        completableFuture.thenRunAsync(() -> System.out.println(22));

        completableFuture.get();
    }
}
